<template>
  <div id="ball-chain">
    <div v-for="(day,index) in list" :key="day.id"
         :style="{height:(index===0?20:80) + 'px'}">
      <div class="line" v-if="index > 0"></div>
      <span class="ball" :class="{anyClick:selectedBall === day.day}"
            @click="switchAndScroll(day)"
            @mouseenter="hoverBall=day.day" @mouseleave="hoverBall=''"></span>
      <span class="text" v-if="selectedBall === day.day || hoverBall === day.day"> {{ day.day }}</span>
    </div>
  </div>
</template>

<script>

export default {
  name: "ball-chain",
  props: ['list', 'currentDay'],
  data() {
    return {
      selectedBall: '',
      hoverBall: ''
    }
  },
  watch: {
    currentDay() {
      this.selectedBall = this.currentDay
    },
    list: {
      handler(nv, ov) {
        ov, this.initFirstDay(nv)
      }
    }
  },
  methods: {
    switchAndScroll(day) {
      this.selectedBall = day.day
      let el = document.getElementById(day.id)
      this.$bus.$emit('scrollTo', el.offsetTop - 10)
    },
    initFirstDay(arr) {
      this.selectedBall = arr[0].day
    }
  },
  mounted() {
    this.initFirstDay(this.list)
  }
}
</script>

<style scoped>

#ball-chain {
  position: fixed;
  right: 80px;
  top: 60px;
  height: 580px;
  overflow: hidden auto;
  scrollbar-width: none;
}

#ball-chain::-webkit-scrollbar {
  display: none;
}

#ball-chain .ball {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 10px;
  background-color: lightgray;
}

#ball-chain .line {
  width: 4px;
  height: 60px;
  background-color: lightgray;
  margin-left: 8px;
}

#ball-chain .text {
  position: fixed;
  right: 25px;
  color: #409EFF;
}
</style>